home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / djet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  24.3 KB  |  953 lines

  1.  
  2.  
  3.    /*************************************************
  4.    *
  5.    *   file d:\cips\djet.c
  6.    *
  7.    *   Functions: This file contains
  8.    *      end_graphics_mode
  9.    *      get_graphics_caption
  10.    *      print_bytes
  11.    *      print_graphics_image
  12.    *      print_original_200_row
  13.    *      select_300_dpi_resolution
  14.    *      select_full_graphics_mode
  15.    *      set_horizontal_offset
  16.    *      set_raster_width
  17.    *      start_raster_graphics
  18.    *
  19.    *   Purpose:
  20.    *      These functions print a 200x200 image using
  21.    *      dithering to an HP DeskJet or compatable 
  22.    *      (Laserjet). This uses an 8x8 matrix which 
  23.    *      gives 64 shades of gray.
  24.    *
  25.    *   External Calls:
  26.    *          rtiff.c - read_tiff_image
  27.    *           hist.c - zero_histogram
  28.    *                    calculate_histogram
  29.    *                    perform_histogram_equalization
  30.    *
  31.    *
  32.    *   Modifications:
  33.    *      January 1991 - created
  34.    *      25 August 1991 - modified for use in the
  35.    *         C Image Processing System.
  36.    *
  37.     ZDDDDD?   ZDDDDD?
  38.     3     3   3     3   The function print_graphics_image
  39.     3     3   3     3   begins with 2 100x100 image arrays
  40.     3     3   3     3
  41.     3     3   3     3
  42.     @DDDDDY   @DDDDDY
  43.  
  44.     ZDDDDDDDDDDDDDDD?
  45.     3               3   It joins them into
  46.     3               3   1 100x200 image array
  47.     3               3
  48.     3               3
  49.     @DDDDDDDDDDDDDDDY
  50.  
  51.     ZDDDDDDDDDDDDDDD?
  52.     @DDDDDDDDDDDDDDDY
  53.     ZDDDDDDDDDDDDDDD?
  54.     @DDDDDDDDDDDDDDDY
  55.            .            It loops and creates
  56.            .            100 200 element image arrays
  57.            .
  58.     ZDDDDDDDDDDDDDDD?
  59.     @DDDDDDDDDDDDDDDY
  60.  
  61.  
  62.           The function print_original_200_row 
  63.           receives a 200 element array
  64.     ZBDDDDDDDDDDDDDDDDDDDDDDDDDDB?
  65.     @ADDDDDDDDDDDDDDDDDDDDDDDDDDAY
  66.  
  67.           This array is transformed into a 8x200 
  68.           array of characters called 'row'
  69.     ZDDDDDDDDD ... ~DDDDDDD?
  70.     CDDDDDDDDD ... ~DDDDDDD4
  71.     CDDDDDDDDD ... ~DDDDDDD4
  72.     CDDDDDDDDD ... ~DDDDDDD4
  73.     CDDDDDDDDD ... ~DDDDDDD4
  74.     CDDDDDDDDD ... ~DDDDDDD4
  75.     CDDDDDDDDD ... ~DDDDDDD4
  76.     CDDDDDDDDD ... ~DDDDDDD4
  77.     @DDDDDDDDD ... ~DDDDDDDY
  78.  
  79.           Each column of this array is a 1x8 character
  80.           array which is an 8-bit x 8-bit array
  81.     IMM;
  82.     :  :
  83.     HMM<
  84.           Each row of 'row' is passed to the funnction 
  85.           print_bytes for graphics printing
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.    ***************************************************/
  93.  
  94.  
  95. #include "cips.h"
  96.  
  97. #define ESCAPE 27
  98. #define FORMFEED  '\014'
  99.  
  100. short r[200];
  101.  
  102.  
  103.  
  104.       /*******************************************
  105.       *
  106.       *   The patterns array holds the rows to the
  107.       *   8x8 matrices used for printing
  108.       *   shades of gray.
  109.       *
  110.       ********************************************/
  111.  
  112. char patterns[64][8] =
  113.    { {255, 255, 255, 255, 255, 255, 255, 255},
  114.      {255, 255, 255, 255, 255, 255, 255, 127},
  115.      {255, 255, 255, 255, 255, 255, 255,  63},
  116.      {255, 255, 255, 255, 255, 255, 255,  31},
  117.      {255, 255, 255, 255, 255, 255, 255,  15},
  118.      {255, 255, 255, 255, 255, 255, 255,   7},
  119.      {255, 255, 255, 255, 255, 255, 255,   3},
  120.      {255, 255, 255, 255, 255, 255, 255,   1},
  121.      {255, 255, 255, 255, 255, 255, 255,   0},
  122.      {255, 255, 255, 255, 255, 255, 127,   0},
  123.      {255, 255, 255, 255, 255, 255,  63,   0},
  124.      {255, 255, 255, 255, 255, 255,  31,   0},
  125.      {255, 255, 255, 255, 255, 255,  15,   0},
  126.      {255, 255, 255, 255, 255, 255,   7,   0},
  127.      {255, 255, 255, 255, 255, 255,   3,   0},
  128.      {255, 255, 255, 255, 255, 255,   1,   0},
  129.      {255, 255, 255, 255, 255, 255,   0,   0},
  130.      {255, 255, 255, 255, 255, 127,   0,   0},
  131.      {255, 255, 255, 255, 255,  63,   0,   0},
  132.      {255, 255, 255, 255, 255,  31,   0,   0},
  133.      {255, 255, 255, 255, 255,  15,   0,   0},
  134.      {255, 255, 255, 255, 255,   7,   0,   0},
  135.      {255, 255, 255, 255, 255,   3,   0,   0},
  136.      {255, 255, 255, 255, 255,   1,   0,   0},
  137.      {255, 255, 255, 255, 255,   0,   0,   0},
  138.      {255, 255, 255, 255, 127,   0,   0,   0},
  139.      {255, 255, 255, 255,  63,   0,   0,   0},
  140.      {255, 255, 255, 255,  31,   0,   0,   0},
  141.      {255, 255, 255, 255,  15,   0,   0,   0},
  142.      {255, 255, 255, 255,   7,   0,   0,   0},
  143.      {255, 255, 255, 255,   3,   0,   0,   0},
  144.      {255, 255, 255, 255,   1,   0,   0,   0},
  145.      {255, 255, 255, 255,   0,   0,   0,   0},
  146.      {255, 255, 255, 127,   0,   0,   0,   0},
  147.      {255, 255, 255,  63,   0,   0,   0,   0},
  148.      {255, 255, 255,  31,   0,   0,   0,   0},
  149.      {255, 255, 255,  15,   0,   0,   0,   0},
  150.      {255, 255, 255,   7,   0,   0,   0,   0},
  151.      {255, 255, 255,   3,   0,   0,   0,   0},
  152.      {255, 255, 255,   1,   0,   0,   0,   0},
  153.      {255, 255, 255,   0,   0,   0,   0,   0},
  154.      {255, 255, 127,   0,   0,   0,   0,   0},
  155.      {255, 255,  63,   0,   0,   0,   0,   0},
  156.      {255, 255,  31,   0,   0,   0,   0,   0},
  157.      {255, 255,  15,   0,   0,   0,   0,   0},
  158.      {255, 255,   7,   0,   0,   0,   0,   0},
  159.      {255, 255,   3,   0,   0,   0,   0,   0},
  160.      {255, 255,   1,   0,   0,   0,   0,   0},
  161.      {255, 255,   0,   0,   0,   0,   0,   0},
  162.      {255, 127,   0,   0,   0,   0,   0,   0},
  163.      {255,  63,   0,   0,   0,   0,   0,   0},
  164.      {255,  31,   0,   0,   0,   0,   0,   0},
  165.      {255,  15,   0,   0,   0,   0,   0,   0},
  166.      {255,   7,   0,   0,   0,   0,   0,   0},
  167.      {255,   3,   0,   0,   0,   0,   0,   0},
  168.      {255,   1,   0,   0,   0,   0,   0,   0},
  169.      {255,   0,   0,   0,   0,   0,   0,   0},
  170.      {127,   0,   0,   0,   0,   0,   0,   0},
  171.      { 63,   0,   0,   0,   0,   0,   0,   0},
  172.      { 31,   0,   0,   0,   0,   0,   0,   0},
  173.      { 15,   0,   0,   0,   0,   0,   0,   0},
  174.      {  7,   0,   0,   0,   0,   0,   0,   0},
  175.      {  3,   0,   0,   0,   0,   0,   0,   0},
  176.      {  1,   0,   0,   0,   0,   0,   0,   0}};
  177.  
  178.  
  179.  
  180.    /************************************************
  181.    *
  182.    *   print_graphics_image(...
  183.    *
  184.    ************************************************/
  185.  
  186. print_graphics_image(image1, image2, image_name,
  187.                      il, ie, ll, le, image_colors,
  188.                      invert, caption, show_hist,
  189.                      color_transform)
  190.    char  caption[], image_name[], color_transform[];
  191.    int   image_colors, invert,
  192.          il, ie, ll, le, show_hist;
  193.    short image1[ROWS][COLS], image2[ROWS][COLS];
  194. {
  195.    char c[80],
  196.         page[80];
  197.  
  198.    FILE *printer;
  199.  
  200.    int  i,
  201.         j;
  202.  
  203.    unsigned long histogram[256], final_hist[256];
  204.    printer = fopen("prn", "w");
  205.  
  206.  
  207.       /**********************************************
  208.       *
  209.       *   Print a few blank lines on the page.
  210.       *
  211.       ***********************************************/
  212.  
  213.    strcpy(page, "                             \n");
  214.    fputs(page, printer);
  215.    fputs(page, printer);
  216.  
  217.  
  218.       /***********************************************
  219.       *
  220.       *   Read in two image arrays.
  221.       *
  222.       ************************************************/
  223.  
  224.    printf("\nReading image");
  225.    read_tiff_image(image_name, image1, il, ie, ll, le);
  226.  
  227.  
  228.    printf("\nReading image");
  229.    read_tiff_image(image_name, image2, 
  230.                    il, ie+100, ll, le+100);
  231.  
  232.  
  233.       /**********************************************
  234.       *
  235.       *   If show_hist is 1 OR do hist equalization
  236.       *   then zero the histogram and
  237.       *   calculate it for the two image arrays.
  238.       *
  239.       ***********************************************/
  240.  
  241.    if( (show_hist == 1)  ||
  242.        (color_transform[0] == 'H')){
  243.       zero_histogram(histogram);
  244.       zero_histogram(final_hist);
  245.       printf("\nDJET> Calculating histograms");
  246.       calculate_histogram(image1, histogram);
  247.       calculate_histogram(image2, histogram);
  248.    }
  249.  
  250.         /*********************************************
  251.         *
  252.         *   Alter the images to 64 gray shades.
  253.         *   Either do it with straight multiply
  254.         *   and divide or use hist equalization.
  255.         *
  256.         *   If using hist equalization then you must
  257.         *   also read and calculate the hist for
  258.         *   the other two image arrays that will be
  259.         *   printed.
  260.         *
  261.         **********************************************/
  262.  
  263.    if(color_transform[0] == 'S'){
  264.    if(image_colors == 256){
  265.       for(i=0; i<ROWS; i++){
  266.          for(j=0; j<COLS; j++){
  267.             image1[i][j] = image1[i][j]/4;
  268.             image2[i][j] = image2[i][j]/4;
  269.         }
  270.       }
  271.    }  /* ends if image_colors == 256 */
  272.  
  273.  
  274.    if(image_colors == 16){
  275.       for(i=0; i<ROWS; i++){
  276.          for(j=0; j<COLS; j++){
  277.             image1[i][j] = image1[i][j]*4;
  278.             image2[i][j] = image2[i][j]*4;
  279.         }
  280.       }
  281.    }  /* ends if image_colors == 16 */
  282.    }  /* ends if color_transform == S */
  283.  
  284.    if(color_transform[0] == 'H'){
  285.  
  286.       printf("\nReading image");
  287.       read_tiff_image(image_name, image1, 
  288.                    il+100, ie, ll+100, le);
  289.       printf("\nReading image");
  290.       read_tiff_image(image_name, image2,
  291.                    il+100, ie+100, ll+100, le+100);
  292.       printf("\nDJET> Calculating histograms");
  293.       calculate_histogram(image1, histogram);
  294.       calculate_histogram(image2, histogram);
  295.  
  296.       printf("\nReading image");
  297.       read_tiff_image(image_name, image1, 
  298.                    il, ie, ll, le);
  299.  
  300.       printf("\nReading image");
  301.       read_tiff_image(image_name, image2, 
  302.                    il, ie+100, ll, le+100);
  303.  
  304.       printf("\nDJET> Equalizing histogram");
  305.       perform_histogram_equalization(image1, histogram,
  306.                                      64.0, 40000.0);
  307.       printf("\nDJET> Equalizing histogram");
  308.       perform_histogram_equalization(image2, histogram,
  309.                                      64.0, 40000.0);
  310.  
  311.       printf("\nDJET> Calculating histograms");
  312.       calculate_histogram(image1, final_hist);
  313.       calculate_histogram(image2, final_hist);
  314.  
  315.  
  316.    }  /* ends if color_transform == H */
  317.  
  318.  
  319.  
  320.       /*********************************************
  321.       *
  322.       *   If invert is set them invert the 
  323.       *   transformed image arrays (they now 
  324.       *   only have 64 shades of gray).
  325.       *
  326.       **********************************************/
  327.  
  328.    if(invert == 1){
  329.       for(i=0; i<ROWS; i++){
  330.          for(j=0; j<COLS; j++){
  331.                image1[i][j] = 63 - image1[i][j];
  332.                image2[i][j] = 63 - image2[i][j];
  333.          }
  334.       }
  335.    }
  336.  
  337.  
  338.  
  339.         /********************************************
  340.         *
  341.         *   Now set the graphics mode on the printer
  342.         *
  343.         *********************************************/
  344.  
  345.    printf("\nBegin");
  346.    end_graphics_mode(printer);
  347.    select_300_dpi_resolution(printer);
  348.    set_raster_width(printer);
  349.    start_raster_graphics(printer);
  350.    select_full_graphics_mode(printer);
  351.  
  352.         /*********************************************
  353.         *
  354.         *   Print the two arrays to make a 100x200 
  355.         *   output. To do this you loop over 100 rows, 
  356.         *   set the r buffer to the image values, set 
  357.         *   the graphics, and print the row via 
  358.         *   function print_original_200_row.
  359.         *
  360.         **********************************************/
  361.  
  362.    for(i=0; i<100; i++){
  363.       for(j=0; j<100; j++){
  364.          r[j]     = image1[i][j];
  365.          r[j+100] = image2[i][j];
  366.       }  /* ends loop over j */
  367.  
  368.       end_graphics_mode(printer);
  369.       select_300_dpi_resolution(printer);
  370.       set_raster_width(printer);
  371.       start_raster_graphics(printer);
  372.       select_full_graphics_mode(printer);
  373.  
  374.       print_original_200_row(printer, r);
  375.  
  376.       printf("\n\tPrinting row %d", i);
  377.    }  /* ends loop over i */
  378.  
  379.            /* ends first half */
  380.  
  381.  
  382.  
  383.       /**********************************************
  384.       *
  385.       *   In order to print 200x200 repeat
  386.       *   the above steps for 2 more 100x100 arrays
  387.       *
  388.       ***********************************************/
  389.  
  390.  
  391.    printf("\nReading image");
  392.    read_tiff_image(image_name, image1, 
  393.                 il+100, ie, ll+100, le);
  394.    printf("\nReading image");
  395.    read_tiff_image(image_name, image2,
  396.                 il+100, ie+100, ll+100, le+100);
  397.  
  398.  
  399.         /*********************************************
  400.         *
  401.         *   Alter the images to 64 shades of gray.
  402.         *
  403.         *   Either do it with straight multiply
  404.         *   and divide or use hist equalization.
  405.         *
  406.         **********************************************/
  407.  
  408.  
  409.    if(color_transform[0] == 'S'){
  410.    if(image_colors == 256){
  411.       for(i=0; i<ROWS; i++){
  412.          for(j=0; j<COLS; j++){
  413.             image1[i][j] = image1[i][j]/4;
  414.             image2[i][j] = image2[i][j]/4;
  415.         }
  416.       }
  417.    }  /* ends if image_colors == 256 */
  418.  
  419.  
  420.    if(image_colors == 16){
  421.       for(i=0; i<ROWS; i++){
  422.          for(j=0; j<COLS; j++){
  423.             image1[i][j] = image1[i][j]*4;
  424.             image2[i][j] = image2[i][j]*4;
  425.         }
  426.       }
  427.    }  /* ends if image_colors == 16 */
  428.    }  /* ends if color_transform == S */
  429.  
  430.  
  431.  
  432.    if(color_transform[0] == 'H'){
  433.  
  434.       printf("\nDJET> Equalizing histogram");
  435.       perform_histogram_equalization(image1, histogram,
  436.                                      64.0, 40000.0);
  437.       printf("\nDJET> Equalizing histogram");
  438.       perform_histogram_equalization(image2, histogram,
  439.                                      64.0, 40000.0);
  440.  
  441.       printf("\nDJET> Calculating histograms");
  442.       calculate_histogram(image1, final_hist);
  443.       calculate_histogram(image2, final_hist);
  444.  
  445.    }  /* ends if color_transform == S */
  446.  
  447.  
  448.  
  449.  
  450.       /************************************************
  451.       *
  452.       *   If invert is set them invert the transformed
  453.       *   image arrays (they now only have 64 shades
  454.       *   of gray).
  455.       *
  456.       *************************************************/
  457.  
  458.    if(invert == 1){
  459.       for(i=0; i<ROWS; i++){
  460.          for(j=0; j<COLS; j++){
  461.                image1[i][j] = 63 - image1[i][j];
  462.                image2[i][j] = 63 - image2[i][j];
  463.          }
  464.       }
  465.    }
  466.  
  467.  
  468.  
  469.    printf("\nBegin");
  470.    end_graphics_mode(printer);
  471.    select_300_dpi_resolution(printer);
  472.    set_raster_width(printer);
  473.    start_raster_graphics(printer);
  474.    select_full_graphics_mode(printer);
  475.  
  476.  
  477.     /***********************************************
  478.     *
  479.     *   Print the two arrays to make a 100x200 output.
  480.     *   To do this you loop over 100 rows, set the
  481.     *   r buffer to the image values, set the
  482.     *   graphics, and print the row via function
  483.     *   print_original_200_row.
  484.     *
  485.     *************************************************/
  486.  
  487.    for(i=0; i<100; i++){
  488.       for(j=0; j<100; j++){
  489.          r[j]     = image1[i][j];
  490.          r[j+100] = image2[i][j];
  491.       }  /* ends loop over j */
  492.  
  493.       end_graphics_mode(printer);
  494.       select_300_dpi_resolution(printer);
  495.       set_raster_width(printer);
  496.       start_raster_graphics(printer);
  497.       select_full_graphics_mode(printer);
  498.  
  499.       print_original_200_row(printer, r);
  500.  
  501.       printf("\n\tPrinting row %d", i);
  502.    }  /* ends loop over i */
  503.  
  504.  
  505.       /**********************************************
  506.       *
  507.       *   If show_hist is 1 then calculate the 
  508.       *   histogram for the two image arrays and 
  509.       *   print the histogram.
  510.       *
  511.       ***********************************************/
  512.  
  513.    if(show_hist == 1){
  514.       if(color_transform[0] == 'S'){
  515.          calculate_histogram(image1, histogram);
  516.          calculate_histogram(image2, histogram);
  517.          print_hist_image(printer, histogram);
  518.       }
  519.       if(color_transform[0] == 'H'){
  520.          print_hist_image(printer, final_hist);
  521.       }
  522.    }
  523.  
  524.         /*********************************************
  525.         *
  526.         *   Print a couple of blank lines then print
  527.         *   the caption.
  528.         *
  529.         **********************************************/
  530.  
  531.    end_graphics_mode(printer);
  532.    strcpy(page, "      \n");
  533.    fputs(page, printer);
  534.    fputs(page, printer);
  535.  
  536.    sprintf(page, "                      %s\n", caption);
  537.    fputs(page, printer);
  538.  
  539.    fputc(FORMFEED, printer);
  540.  
  541.    fclose(printer);
  542.  
  543.    printf("\nEnd");
  544.  
  545. }  /* ends print_graphics_image */
  546.  
  547.  
  548.  
  549.    /******************************************
  550.    *
  551.    *   get_graphics_caption(...
  552.    *
  553.    ******************************************/
  554.  
  555. get_graphics_caption(caption)
  556.    char caption[];
  557. {
  558.    printf("\nEnter the caption to be printed\n---");
  559.    gets(caption);
  560.  
  561. }  /* ends get_graphics_caption */
  562.  
  563.  
  564.  
  565.  
  566.    /************************************************
  567.    *
  568.    *   select_full_graphics_mode(...
  569.    *
  570.    ************************************************/
  571.  
  572. select_full_graphics_mode(printer)
  573.  
  574.    FILE *printer;
  575. {
  576.    fputc(ESCAPE, printer);
  577.    fputc('*', printer);
  578.    fputc('b', printer);
  579.    fputc('0', printer);
  580.    fputc('M', printer);
  581.  
  582. }
  583.  
  584.  
  585.  
  586.    /************************************************
  587.    *
  588.    *   set_horizontal_offset(...
  589.    *
  590.    ************************************************/
  591.  
  592. set_horizontal_offset(printer)
  593.  
  594.    FILE *printer;
  595. {
  596.    fputc(ESCAPE, printer);
  597.    fputc('*', printer);
  598.    fputc('b', printer);
  599.    fputc('4', printer);
  600.    fputc('9', printer);
  601.    fputc('6', printer);
  602.    fputc('X', printer);
  603.  
  604. }
  605.  
  606.  
  607.  
  608.  
  609.  
  610.    /************************************************
  611.    *
  612.    *   set_shorter_horizontal_offset(...
  613.    *
  614.    ************************************************/
  615.  
  616. set_shorter_horizontal_offset(printer)
  617.  
  618.    FILE *printer;
  619. {
  620.    fputc(ESCAPE, printer);
  621.    fputc('*', printer);
  622.    fputc('b', printer);
  623.    fputc('4', printer);
  624.    fputc('8', printer);
  625.    fputc('0', printer);
  626.    fputc('X', printer);
  627.  
  628. }
  629.  
  630.  
  631.  
  632.  
  633.  
  634.    /************************************************
  635.    *
  636.    *   end_graphics_mode(...
  637.    *
  638.    ************************************************/
  639.  
  640. end_graphics_mode(printer)
  641.    FILE *printer;
  642. {
  643.    fputc(ESCAPE, printer);
  644.    fputc('*', printer);
  645.    fputc('r', printer);
  646.    fputc('B', printer);
  647. }
  648.  
  649.  
  650.  
  651.    /************************************************
  652.    *
  653.    *   set_raster_width(...
  654.    *
  655.    ************************************************/
  656.  
  657. set_raster_width(printer)
  658.  
  659.    FILE *printer;
  660. {
  661.    fputc(ESCAPE, printer);
  662.    fputc('*', printer);
  663.    fputc('r', printer);
  664.    fputc('2', printer);
  665.    fputc('2', printer);
  666.    fputc('0', printer);
  667.    fputc('0', printer);
  668.    fputc('S', printer);
  669.  
  670. }
  671.  
  672.  
  673.  
  674.  
  675.    /************************************************
  676.    *
  677.    *   start_raster_graphics(...
  678.    *
  679.    ************************************************/
  680.  
  681. start_raster_graphics(printer)
  682.  
  683.    FILE *printer;
  684. {
  685.    fputc(ESCAPE, printer);
  686.    fputc('*', printer);
  687.    fputc('r', printer);
  688.    fputc('0', printer);
  689.    fputc('A', printer);
  690.  
  691. }
  692.  
  693.  
  694.  
  695.  
  696.    /************************************************
  697.    *
  698.    *   select_300_dpi_resolution(...
  699.    *
  700.    ************************************************/
  701.  
  702. select_300_dpi_resolution(printer)
  703.  
  704.    FILE *printer;
  705. {
  706.    fputc(ESCAPE, printer);
  707.    fputc('*', printer);
  708.    fputc('t', printer);
  709.    fputc('3', printer);
  710.    fputc('0', printer);
  711.    fputc('0', printer);
  712.    fputc('R', printer);
  713.  
  714. }
  715.  
  716.  
  717.  
  718.  
  719.    /************************************************
  720.    *
  721.    *   print_bytes(...
  722.    *
  723.    ************************************************/
  724.  
  725. print_bytes(printer, buffer)
  726.    FILE *printer;
  727.    char buffer[];
  728. {
  729.    int        i;
  730.  
  731.    fputc(ESCAPE, printer);
  732.    fputc('*', printer);
  733.    fputc('b', printer);
  734.    fputc('2', printer);
  735.    fputc('0', printer);
  736.    fputc('0', printer);
  737.    fputc('W', printer);
  738.  
  739.  
  740.    for(i=0; i<200; i++){
  741.       fputc(buffer[i], printer);
  742.    }
  743. }  /* ends print_bytes */
  744.  
  745.  
  746.  
  747.  
  748.    /**************************************************
  749.    *
  750.    *   print_original_200_row(...
  751.    *
  752.    ***************************************************/
  753.  
  754. print_original_200_row(printer, short_row)
  755.    FILE  *printer;
  756.    short short_row[200];
  757. {
  758.    char  row[8][200];
  759.    char  c[200], response[80];
  760.    int         i, j, k;
  761.    short value;
  762.    for(i=0; i<200; i++){
  763.       value = short_row[i];
  764.       if(value > 63) value = 63;
  765.       if(value < 0)  value =  0;
  766.  
  767.       for(j=0; j<8; j++)
  768.          row[j][i] = patterns[value][j];
  769.  
  770.    }  /* ends loop over i */
  771.  
  772.    for(i=0; i<8; i++){
  773.       for(j=0; j<200; j++)
  774.          c[j] = row[i][j];
  775.       set_horizontal_offset(printer);
  776.       print_bytes(printer, c);
  777.    }  /* ends loop over i */
  778.  
  779. }  /* ends print_original_200_row */
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.    /***********************************
  787.    *
  788.    *   print_hist_image(...
  789.    *
  790.    ************************************/
  791.  
  792. print_hist_image(printer, hist)
  793.    FILE *printer;
  794.    unsigned long hist[];
  795. {
  796.    char   c, d;
  797.    int          i, j, k;
  798.    unsigned long limit, max;
  799.  
  800.    d = 0;
  801.    c = 255;
  802.  
  803.       /********************************
  804.       *
  805.       *   First scale the histogram
  806.       *
  807.       *********************************/
  808.  
  809.    max = 0;
  810.    for(i=0; i<256; i++)
  811.       if(hist[i] > max) max = hist[i];
  812.  
  813.    if(max > 200){
  814.       for(i=0; i<256; i++){
  815.         hist[i] = (hist[i]*200)/max;
  816.       }
  817.    }
  818.  
  819.  
  820.       /********************************
  821.       *
  822.       *   Second print it
  823.       *
  824.       *   Print a space between the image
  825.       *   and the histogram.
  826.       *
  827.       *********************************/
  828.  
  829.  
  830.    for(i=0; i<20; i++){
  831.          end_graphics_mode(printer);
  832.          select_300_dpi_resolution(printer);
  833.          set_raster_width(printer);
  834.          start_raster_graphics(printer);
  835.          select_full_graphics_mode(printer);
  836.          set_horizontal_offset(printer);
  837.          fputc(ESCAPE, printer);
  838.          fputc('*', printer);
  839.          fputc('b', printer);
  840.          fputc('2', printer);
  841.          fputc('0', printer);
  842.          fputc('0', printer);
  843.          fputc('W', printer);
  844.  
  845.          for(j=0; j<200; j++)
  846.             fputc(d, printer);
  847.    }
  848.  
  849.  
  850.    printf("\n\nHIST> Now printing the histogram");
  851.    for(i=0; i<256; i++){
  852.       printf("\n\tHIST> Histogram[%d]=%ld", 
  853.             i, hist[i]);
  854.  
  855.             /* print the line 2 times */
  856.       for(k=0; k<2; k++){
  857.  
  858.          end_graphics_mode(printer);
  859.          select_300_dpi_resolution(printer);
  860.          set_raster_width(printer);
  861.          start_raster_graphics(printer);
  862.          select_full_graphics_mode(printer);
  863.  
  864.  
  865.             /***************************
  866.             *
  867.             *  Print grid marks every
  868.             *  50 pixels.  Do this by
  869.             *  setting a shorter margin
  870.             *  then printing 2 marks then
  871.             *  the data.
  872.             *
  873.             ****************************/
  874.  
  875.          if( (i ==   0) ||
  876.              (i ==  50) ||
  877.              (i == 100) ||
  878.              (i == 150) ||
  879.              (i == 200) ||
  880.              (i == 255)){
  881.  
  882.             set_shorter_horizontal_offset(printer);
  883.             fputc(ESCAPE, printer);
  884.             fputc('*', printer);
  885.             fputc('b', printer);
  886.             fputc('2', printer);
  887.             fputc('0', printer);
  888.             fputc('2', printer);
  889.             fputc('W', printer);
  890.  
  891.             fputc(c, printer);
  892.             fputc(c, printer);
  893.  
  894.  
  895.             if(hist[i] >= 200)
  896.                hist[i] = 200;
  897.  
  898.             limit = 200 - hist[i];
  899.  
  900.             if(hist[i] == 0)
  901.                fputc(c, printer);
  902.  
  903.             for(j=0; j<hist[i]; j++)
  904.                fputc(c, printer);
  905.  
  906.             for(j=0; j<limit; j++)
  907.               fputc(d, printer);
  908.  
  909.          }  /* ends print grid marks */
  910.  
  911.  
  912.             /***************************
  913.             *
  914.             *  If you do not print
  915.             *  grid marks, set the normal
  916.             *  margin and then print the
  917.             *  data.
  918.             *
  919.             ****************************/
  920.  
  921.          else{
  922.             set_horizontal_offset(printer);
  923.             /* this prints 200 bytes so print 200 */
  924.             fputc(ESCAPE, printer);
  925.             fputc('*', printer);
  926.             fputc('b', printer);
  927.             fputc('2', printer);
  928.             fputc('0', printer);
  929.             fputc('0', printer);
  930.             fputc('W', printer);
  931.  
  932.             if(hist[i] >= 200)
  933.                hist[i] = 200;
  934.  
  935.             limit = 200 - hist[i];
  936.  
  937.             if(hist[i] == 0)
  938.                fputc(c, printer);
  939.  
  940.             for(j=0; j<hist[i]; j++)
  941.                fputc(c, printer);
  942.  
  943.             for(j=0; j<limit; j++)
  944.               fputc(d, printer);
  945.  
  946.          }  /* ends else no grid marks */
  947.  
  948.       }  /* ends loop over k */
  949.  
  950.    }  /* ends loop over i */
  951.  
  952. }  /* ends print_hist_image */
  953.